package com.zerocarbon.framework.common.enums;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zerocarbon.framework.common.extension.IBaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum YesNoFlag implements IBaseEnum {

	YES(1, "是"),

	NO(0, "否"),

	;

	private Integer val;
	private String desc;


	public static YesNoFlag match(String val, YesNoFlag def) {
		for (YesNoFlag enm : YesNoFlag.values()) {
			if (enm.name().equalsIgnoreCase(val)) {
				return enm;
			}
		}
		return def;
	}

	public static YesNoFlag get(String val) {
		return match(val, null);
	}

	public boolean eq(String val) {
		return this.name().equalsIgnoreCase(val);
	}

	public boolean eq(YesNoFlag val) {
		if (val == null) {
			return false;
		}
		return eq(val.name());
	}

	@Override
	public String getCode() {
		return this.name();
	}

	public static String getDescByVal(Integer val) {
		for (YesNoFlag enm : YesNoFlag.values()) {
			if (enm.val.equals(val)) {
				return enm.desc;
			}
		}
		return null;
	}

	public static Integer getValByDesc(String desc) {
		for (YesNoFlag enm : YesNoFlag.values()) {
			if (enm.desc.equals(desc)) {
				return enm.val;
			}
		}
		return null;
	}

	public static YesNoFlag getYesNoFlag(int value) {
		for (YesNoFlag accountBindType : YesNoFlag.values()) {
			if (accountBindType.getVal() == value) return accountBindType;
		}
		return null;
	}
	
	
}
